package action.login;

import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import services.login.LoginServices;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.*;
import com.syslog.SysLogServices;
import com.util.Component;
import com.util.Util;
/**
* PersonMgrFacade:登录action
* @author bjh
* @version Fri May 06 17:59:17 CST 2016 gjx
* @since 1.0
*/
@Controller
@RequestMapping("login.do")
public class LoginAction {
	LoginServices ls = new LoginServices();
	PublicSystem sys = PublicSystem.getInstance();
	SysLogServices log = SysLogServices.getInstance();
	@RequestMapping(params = "method=login1")
    public void Login(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//取json数据转换
    	HashMap map = (HashMap)Util.Decode(request.getParameter("submitData"));
    	//登录用户session
    	HttpSession session = request.getSession();
        session.setAttribute("userid", (String)map.get("username"));
        HashMap obj = new HashMap();
		obj.put("domainid", "SBK");
		obj.put("log_type", "T01");
		obj.put("userid", (String)map.get("username"));
		obj.put("rwh", Component.getSession("rwid", request));
		obj.put("content", "登录系统");
		obj.put("czqd", "Q1");
		obj.put("czrlb", "L01"); 
		obj.put("datain", (String)map.get("username"));
		obj.put("dataout", "success");
		log.sysLogMap(obj, request);
        //返回处理结果
        Component.print(ls.getUser(map), response);
    }
	/**
	 * 登录过期
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=ForWard")
    public void ForWard(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String admin = (String) request.getSession().getAttribute("userid");
		String id = Component.getQuest("id", request);
		
		if (admin == null) {
			Component.messageUrl("登录已过期，请重新登陆", "/" + Const.project, response);
		} else {
			request.getSession().setAttribute("rwid", id);
			request.getRequestDispatcher(ls.getUrl(id)).forward(request, response);
		}
    }
}
